package com.bruce.pattern.behavioral.chain.demo2;

/**
 * Created by bruce on 2018/11/11 17:17
 */
public abstract class ChainHandler<T> {

    private ChainHandler<T> nextHandler;

    public ChainHandler<T> nextHandler(ChainHandler<T> chainHandler) {
        this.nextHandler = chainHandler;
        return chainHandler;
    }

    public final void execute(T object) {
        handle(object);
        if (nextHandler != null) {
            nextHandler.execute(object);
        }
    }

    protected abstract void handle(T object);


}
